<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        body{
            padding-bottom: 800px;
        }
        .box-a{
            height: 200px;
            width: 200px;
            background-color: burlywood;
            opacity: 1;
            /* transition: opacity 4s ease; */
        }
        .show{
            opacity: 1;
        }
        .active{
            transition: all 4s ease;
        }
        .hide{
            opacity: 0;
        }
        .item{
            margin: 10px 0px;
            background-color: #ccc;
        }
        .active1{
            transition: all 500ms ease;
        }
        .show1{
            transform: translate(0,0);
            opacity: 1;
        }
        .hide1-1{
            transform: translate(100%,0);
            opacity: 0;
        }
        .hide1-2{
            transform: translate(-100%,0);
            opacity: 0;
        }
    </style>
</head>
<body>
    <div id="app">
        <!-- <transition
            enter-from-class="hide" enter-active-class="active" enter-to-class="show"
            leave-from-class="show" leave-active-class="active" leave-to-class="hide"
        >
            <div v-if="flag" class="box-a">
                <h1>div-a</h1>
            </div>
            <div v-if="flag1" class="box-a"></div>
        </transition> -->

        <!-- 
            可以一次项将动画绑定给内部的多个元素或者组件 
            vue 为了保证动画和多元素的对应关系，要求必须为内部每个元素提供一个唯一key值
            vue操作时可以快速定位执行动画的元素
        -->
        <transition-group
            enter-from-class="hide" enter-active-class="active" enter-to-class="show"
            leave-from-class="show" leave-active-class="active" leave-to-class="hide"
        >
            <div v-if="flag" class="box-a" key="item-a">
                <h1>div-a</h1>
            </div>
            <div v-if="flag1" class="box-a" key="item-b">
                <h1>div-b</h1>
            </div>
        </transition-group>

        <input type="button" value="显示|隐藏" @click=" flag=!flag ">
        <input type="button" value="显示|隐藏" @click=" flag1=!flag1 ">
        <hr>

        <input type="button" value="add" @click="arr.push( Math.random() )">

        <ul>
            <transition-group
                enter-from-class="hide1-1" enter-active-class="active1" enter-to-class="show1"
                leave-from-class="show1" leave-active-class="active1" leave-to-class="hide1-2"
            >
                <li class="item" v-for="(item,i) in arr" :key="item">
                    {{ item }}
                    <input type="button" value="x" @click=" arr.splice(i,1) ">
                </li>
            </transition-group>
        </ul>
    </div>
    <script type="module"> 
        import { createApp } from "../../assets/vue3/vue.esm-browser.js";
        createApp({
            data(){
                return {
                    flag:true,
                    flag1:true,
                    arr:[
                        Math.random(),
                        Math.random(),
                        Math.random(),
                        Math.random(),
                        Math.random()
                    ]
                }
            }
        }).mount("#app")
    </script>
</body>
</html>